<%@ Page Title="Portals" Language="C#" MasterPageFile="~/Views/Shared/ControlPanel.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content4" ContentPlaceHolderID="SubHeaderContent" runat="server">
Portals
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">

    <script src="../../Scripts/jqGrid/grid.locale-en.js" type="text/javascript"></script>
    <script src="../../Scripts/jqGrid/jquery.jqGrid.min.js" type="text/javascript"></script>

    <link href="../../Scripts/jqGrid/ui.jqgrid.css" rel="stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <table id="grid" cellpadding="0" cellspacing="0" ></table>
    <div id="pager" style="text-align:center;"></div>
    <script language="javascript" type="text/javascript">      
        $(document).ready(function() {
            Grid.setupGrid($("#grid"), $("#pager"));
        });

        Grid = {
            setupGrid: function(grid, pager) {
                grid.jqGrid({
                    colNames: ['ID', 'PortalName', 'Description', 'KeyWords'],
                    colModel: [
                    { name: 'PortalID', index: 'PortalID', key: true, editable: false, sortable: true },
                    { name: 'PortalName', index: 'PortalName', width: "150", editable: true, sortable: true, edittype: 'text', editoptions: { size: 30, maxlength: 50 }, editrules: { required: true} },
                    { name: 'Description', index: 'Description', width: "250", editable: true, sortable: false, edittype: 'textarea', editoptions: { rows: "4", cols: "50" }, editrules: { required: false} },
                    { name: 'KeyWords', index: 'KeyWords', width: "250", editable: true, sortable: false, edittype: 'textarea', editoptions: { rows: "4", cols: "50" }, editrules: { required: false} }
                ],
                    pager: pager,
                    sortname: 'PortalID',
                    rowNum: 10,
                    rowList: [10, 20, 50],
                    sortorder: "asc",                   
                    //caption: "ABM Portals",
                    url: 'IndexData'
                }).navGrid(pager, { edit: true, add: true, del: true, search: false },
                { afterSubmit: CallBackAfterSubmit, width: 400, url: "Edit" },
                { afterSubmit: CallBackAfterSubmit, width: 400, url: "Create" },
                { afterSubmit: CallBackAfterSubmit, url: "Delete" }
                )
                /*.navButtonAdd("#pager", {
                    caption: "",
                    title: "Edit selected row",
                    buttonicon: "ui-icon-pencil",
                    onClickButton: function() {
                        var rowid = grid.getGridParam('selrow');
                        if (rowid) {
                            var id = grid.getRowData(rowid)["PortalID"];
                            window.location.href = "Edit/" + id;
                        } else {
                            alert("Please select Row")
                        }
                    },
                    position: "first"
                })
                .navButtonAdd("#pager", {
                    caption: "",
                    title: "Add new row",
                    buttonicon: "ui-icon-plus",
                    onClickButton: function() {
                        window.location.href = "Create";
                    },
                    position: "first"
                });*/

            }
        };
        function CallBackAfterSubmit(r, d) {
            var json = r.responseText;
            var result = eval('('+json+')');
            var messeges = "";
            
            if (!result.Successfull) {
                for (var err in result.Errors) {
                    var propertyName = result.Errors[err].PropertyName;
                    var errorMessage = result.Errors[err].Error;
                    var message = propertyName + ': ' + errorMessage;

                    messeges = messeges + message;
                }
            }

            return [result.Successfull, messeges];             
        }        
    </script>
</asp:Content>
